<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageUri}.web.dao.${className}Dao">

    <select id="getInfoById" resultType="${packageUri}.web.entity.${className}">
        SELECT
        <#list fieldList as field>
            <#if field != '' && field ??>
                ${field.columnName}<#sep>,
            </#if>
        </#list>

        FROM ${tableName} WHERE id = <#noparse>#{id}</#noparse>
    </select>

    <select id="list" resultType="${packageUri}.web.entity.${className}">
        SELECT
        <#list fieldList as field>
            <#if field != '' && field ??>
                ${field.columnName}<#sep>,
            </#if>
        </#list>

        FROM ${tableName}
    </select>

    <update id="delete">
        UPDATE ${tableName}
        <set>
            state = '1'
        </set>
        <where>
            id = <#noparse>#{id}</#noparse>
        </where>
    </update>

    <insert id="insert">
        INSERT INTO ${tableName} (
        <#list attrs as field>
        <#if field != '' && field ??>
            ${field.columnName}<#sep>,
        </#if>
        </#list>)
        VALUES
        (
        <#list attrs as attr>
            <#if attr != '' && attr ??>
                <#if attr.type == "Long" || attr.type = "Integer">
                    <if test="${attr.name} ! = null">
                        <#noparse>#{</#noparse>${attr.name}<#noparse>}</#noparse><#sep>,</#sep>
                    </if>
                <#else>
                    <if test="${attr.name} ! = null and ${attr.name} != ''">
                        <#noparse>#{</#noparse>${attr.name}<#noparse>}</#noparse><#sep>,</#sep>
                    </if>
                </#if>
            </#if>
        </#list>
        )
    </insert>

    <update id="update">
        UPDATE ${tableName}
        <set>
            <#list attrs as attr>
                <#if attr != '' && attr ??>
                    <#if attr.type == "Long" || attr.type = "Integer">
                        <if test="${attr.name} != null">
                            ${attr.columnName} = <#noparse>#{</#noparse>${attr.name}<#noparse>}</#noparse><#sep>,</#sep>
                        </if>
                    <#else>
                        <if test="${attr.name} != null and ${attr.name} != ''">
                            ${attr.columnName} = <#noparse>#{</#noparse>${attr.name}<#noparse>}</#noparse><#sep>,</#sep>
                        </if>
                    </#if>
                </#if>
            </#list>
        </set>
        <where>
            id = <#noparse>#{id}</#noparse>
        </where>
    </update>

</mapper>
